.section .data
data_items:                     #These are the data items
.long 3,67,34,222,45,75,54,34,44,33,22,11,66,0

.section .text
.globl _start
_start:
push data_items,%esp
call fmax             	#run the square function
addl $4, %esp   	#Scrubs the parameter that was pushed on
                        #the stack
movl %eax, %ebx         #square returns the answer in %eax, but
                        #we want it in %ebx to send it as our exit
                        #status

movl $1, %eax           #call the kernel's exit function
int $0x80

#
#This is the actual function definition
#
.type fmax,@function
fmax:
pushl %ebp              #standard function stuff - restore %ebp to
                        #its prior state before returning.
movl %esp, %ebp         #This is because we don't want to modify
                        #the stack pointer, so we use %ebp.
movl 8(%ebp), %eax      #This moves the first argument to %eax
                        #4(%ebp) holds the return address, and
                        #8(%ebp) holds the first parameter
imull %eax, %eax        #multiply for square result
                        #the answer is stored in %eax, return
                        #values always go to %eax.
movl %ebp, %esp         #standard function return stuff - we
popl %ebp               #have to restore %ebp and %esp to where
                        #they were before the function started
ret                     #return to the function



##################################
.type fmax,@function
fmax:
pushl %ebp              #standard function stuff - restore %ebp to
                        #its prior state before returning.
movl %esp, %ebp         #This is because we don't want to modify
                        #the stack pointer, so we use %ebp.

movl $0, %edi                   # move 0 into the index register
movl data_items(,%edi,4), %eax  # load the first byte of data
movl %eax, %ebx                 # since this is the first item, %eax is
                                # the biggest

start_loop:                     # start loop
cmpl $0, %eax                   # check to see if we¡¯ve hit the end
je loop_exit
incl %edi                       # load next value
movl data_items(,%edi,4), %eax
cmpl %ebx, %eax                 # compare values
jle start_loop                  # jump to loop beginning if the new
                                # one isn¡¯t bigger
movl %eax, %ebx                 # move the value as the largest

jmp start_loop                  # jump to loop beginning
loop_exit:
ret
